#include"vlan.h"
#include"ip.h"
#include"mpls.h"

VLANHeader_t * vlan_header;

void init_vlan(FILE *fp){
    vlan_header = (VLANHeader_t *)malloc(sizeof(VLANHeader_t));
    memset(vlan_header, 0, sizeof(VLANHeader_t));
    if (fread(vlan_header, sizeof(VLANHeader_t), 1, fp) != 1){
        printf(" can not read vlan_header\n");
    }
}

int get_vlan_type(){
    return ntohs(vlan_header->VlanType);
}

void free_vlan(){
    free(vlan_header);
}

void process_vlan(FILE *fp){
    init_vlan(fp);
    printf("Vlan ......\n");
    
    switch (get_vlan_type()){
        case VLAN_TYPE_IP:
            process_ip(fp);
            break;
        case VLAN_TYPE_VLAN:
            process_vlan(fp);
            break;
        case VLAN_TYPE_MPLS:
            process_mpls(fp);
            break;
        default:
            printf("next part is not ip or vlan or mpls\n");
            break;
    }
}